//
//  OPMLFile.swift
//  RssFly
//
//  Created by shen on 2023/10/17.
//

import SwiftUI
import UniformTypeIdentifiers

struct OPMLFile: FileDocument {
    static var readableContentTypes = [UTType(importedAs: "public.opml"), .xml]

    var data = Data()

    init(initialData: Data) {
        data = initialData
    }

    init(configuration: ReadConfiguration) throws {
        if let fileData = configuration.file.regularFileContents {
            data = fileData
        }
    }

    func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
        return FileWrapper(regularFileWithContents: data)
    }
}
